package com.wust.tieshi;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import com.wust.R;
import com.wust.footprint.FirstActivity;
import com.wust.menu.FirstGroupTab;
import com.wust.menu.ImageBtn;
import com.wust.menu.SecondGroupTab;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class ViewTestActivity extends ListActivity  {
    /** Called when the activity is first created. */
	private ImageBtn btn1=null;
	private ListView listview=null;
	private ArrayList<HashMap<String, Object>> listItems;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        setContentView(R.layout.two);
        btn1=(ImageBtn)findViewById(R.id.btn1);
       
        btn1.setOnClickListener(new OnListener());
        listview=getListView();
		listview.setAdapter(buildAdapter());
    }
    private  SimpleAdapter buildAdapter(){
		listItems = new ArrayList<HashMap<String, Object>>();    	
        HashMap<String, Object> map1 = new HashMap<String, Object>();           
        map1.put("imageview", R.drawable.growcharm);//图片   
        map1.put("title", "成长走势");     //文字   
        listItems.add(map1); 
        HashMap<String, Object> map2 = new HashMap<String, Object>();          
        map2.put("imageview", R.drawable.healthcheck);//图片    
        map2.put("title", "健康评测");     //文字 
        listItems.add(map2);
        HashMap<String, Object> map3 = new HashMap<String, Object>();        
        map3.put("imageview", R.drawable.notice);//图片   
        map3.put("title", "事件提醒");     //文字 
        listItems.add(map3);
           
        //生成适配器的Item和动态数组对应的元素       
        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItems,//数据源        
            R.layout.first_list,//ListItem的XML布局实现       
            //动态数组与ImageItem对应的子项               
            new String[] {"imageview", "title"},        
            //ImageItem的XML文件里面的一个ImageView,两个TextView ID       
            new int[] {R.id.imageview, R.id.title}       
        ); 
        return listItemAdapter;
	}
	private void buildList(){
		listview.setAdapter(buildAdapter());
	}
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		
		super.onListItemClick(l, v, position, id);
		//要跳转的Activity  
		switch((int)id){
		
		case 0:
			jumptoActivity(charmActivity.class,"charmActivity",null,null);
			break;
		case 1:
			jumptoActivity(AutoCheckActivity.class,"AutoCheckActivity",null,null);
			break;
		case 2:
			jumptoActivity(noticeActivity.class,"noticeActivity",null,null);
			break;
		}	
	}
	private void jumptoActivity(Class activity,String activityname ,String key[],String value[]){
		Intent intent = new Intent(ViewTestActivity.this, activity);  
		if(key!=null&&value!=null&&key.length==value.length)
		
			for(int i=0;i<key.length;++i)
				intent.putExtra(key[i], value[i]);
//			intent.putExtra("user_id",user_id);
		
	
        // 把Activity转换成一个Window，然后转换成View  
        Window w = SecondGroupTab.group.getLocalActivityManager()  
                .startActivity(activityname,intent);  
        View view = w.getDecorView();  
        //设置要跳转的Activity显示为本ActivityGroup的内容  
        SecondGroupTab.group.setContentView(view); 
	}
    class OnListener implements OnClickListener{
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		Toast.makeText(getApplicationContext(), "点击的正确按钮",1).show();
    	}
    }
    
}